﻿using System;
using System.Data;
using Ue.Framework.Data;
using Ue.Qcdz.Domain.Tags;
using Ue.Qcdz.Domain.ContentTypes;
using Ue.Infrastructure.EntityFactoryFramework;

namespace Ue.Qcdz.Repositories.Tags
{
    internal class TagFactory : IEntityFactory<Tag>
    {
        internal class FieldNames : FieldNamesBase
        {
            public const string ContentTypeIdInTags = "ContentTypeId";
            public const string TagName = "Name";  
            public const string Descritpion = "Description";
        }

        #region IEntityFactory<Tag>

        public Tag BuildEntity(IDataReader reader)
        {
            var contentTypeId = reader.Get<Guid>(TagFactory.FieldNames.ContentTypeIdInTags);

            ContentType contentType = ContentTypeService.Instance.FindBy(contentTypeId);

            return new TagProxy(
                contentType,
                reader.Get<Guid>(TagFactory.FieldNames.EntityKey),
                reader.Get<string>(TagFactory.FieldNames.TagName),
                reader.Get<string>(TagFactory.FieldNames.Descritpion),
                reader.Get<DateTime>(TagFactory.FieldNames.CreateOn));
        }

        #endregion
    }
}
